//角色管理模块接口
import request from '@/utils/request.ts'
import { MenuResponseData, RoleResponseData } from '@/api/acl/role/type.ts'
import { RoleData } from '@/api/acl/user/type.ts'

//枚举地址
enum API {
  //获取全部角色的接口
  ALLROLE_URL = '/admin/acl/role/',
  //新增角色的接口
  ADDROLE_URL = '/admin/acl/role/save',
  //修改已有角色的接口
  UPDATEROLE_URL = '/admin/acl/role/update',
  //删除已有的职位
  REMOVEROLE_URL = '/admin/acl/role/remove/',
  //批量删除的接口
  DELETEALLROLE_URL = '/admin/acl/role/batchRemove',
  //获取全部菜单与按钮的数据
  ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
  //给相应的角色职位分配权限
  SETPERMISSION_URL = '/admin/acl/permission/doAssign/?'
}

//获取全部的角色
export const reqRoleInfo = (page: number, limit: number, roleName: string) =>
  request.get<any, RoleResponseData>(API.ALLROLE_URL + `${page}/${limit}?roleName=${roleName}`)

//添加与更新接口
export const reqAddOrUpdateRole = (data: RoleData) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEROLE_URL, data)
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data)
  }
}
//删除已有职位接口
export const reqDeleteRole = (roleId: number) =>
  request.delete<any, any>(API.REMOVEROLE_URL + roleId)
//批量删除职位接口
export const reqSelectRole = (idList: number[]) => request.delete(API.DELETEALLROLE_URL, { data: idList })

//获取全部菜单与按钮权限接口
export const reqAllMenuList = (roleId: number) =>
  request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + roleId)
//给相应的角色职位下发权限
export const reqSetPermission = (roleId: number, permissionId: number[]) =>
  request.post(API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionId}`)